package log

import (
	"fmt"
	"log"
	"os"
)

func Log_1() {
	defer fmt.Println("发生了panic错误")
	log.Print("my log")
	log.Printf("my log %d", 100)
	name := "tom"
	age := 20
	log.Println(name, ",", age)

	//log.Panic("错误1")
	log.Fatal("致命错误")
	fmt.Println("end ")

}

func Log_2() {
	i := log.Flags()
	fmt.Printf("i: %v\n", i)
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	log.Print("my log")

	s := log.Prefix()
	fmt.Printf("s: %v\n", s)
	log.SetPrefix("Requset: ")
	s = log.Prefix()
	fmt.Printf("s: %v\n", s)
	log.Print("my log")
}

func Log_3() {
	f, err := os.OpenFile("a.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
	if err != nil {
		log.Panic("打开文件出错")
	}
	log.SetOutput(f)
	log.Print("my log")
}

func Log_4() {
	f, err := os.OpenFile("a.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
	if err != nil {
		log.Panic("打开文件出错")
	}
	logger := log.New(f, "Request: ", log.Ldate|log.Ltime|log.Lshortfile)
	logger.Print("hahahhahhha")

}
